from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys


wd = webdriver.Chrome(service=Service(f".\chromedriver_win136.exe"))
wd.get("https://www.selenium.dev/selenium/web/web-form.html")
time.sleep(3)
date_picker = wd.find_element(By.NAME, "my-date")

# Method 1: Send keys directly (YYYY-MM-DD format)

date_to_set = "2025-07-15"  # Example: July 15, 2025
date_picker.send_keys(date_to_set)

date_picker.send_keys(Keys.ENTER)
# # Some browsers/inputs might require pressing Enter or Tab to confirm the date
# # or
# # date_picker.send_keys(Keys.TAB)

# print(f"Date set to: {date_picker.get_attribute('value')}")
# time.sleep(3)  # Pause to observe

# Example of sending keys for a different date format if the browser supports it
# (less reliable than YYYY-MM-DD)
# For Chrome, sending keys like "07152025" (MMDDYYYY) often works and it auto-formats.
# date_picker.send_keys("09")  # Month
# time.sleep(3)
# date_picker.send_keys("20")  # Day
# time.sleep(3)
# date_picker.send_keys("2026")  # Year
# time.sleep(3)
# date_picker.send_keys(Keys.ENTER)
# You might need to send Keys.TAB or Keys.ENTER after this for the value to fully register
# or for the calendar popup (if any) to close.

print(f"Date changed to: {date_picker.get_attribute('value')}")
time.sleep(5)
wd.quit()
